package org.webscale;
import java.io.Serializable;

public abstract class BaseDomainObject<T> implements  DomainObject {
	    private static final long serialVersionUID = -7959564056205603596L;
	
	    private String mapperName = null;
	    private Class mapperClazz = null;
	    
	  
	    public BaseDomainObject(String mapperName) {
			  super();
			  this.mapperName = mapperName;
		}
	    /**
	     * {@inheritDoc}
	     */
	    @SuppressWarnings("unchecked")
	    public T getMapper() {
	        return (T) ApplicationController.instance().locateObject(mapperName);
	    }
	    @SuppressWarnings("unchecked")	   
	    public BaseMapper getAnyMapper(String mapperName){
	    	return (BaseMapper) ApplicationController.instance().locateObject(mapperName);
	    }
	    
	    /**
	     * {@inheritDoc}
	     */
	    @SuppressWarnings("unchecked")
	    public T getMapper(String name) {
	        return (T) ApplicationController.instance().locateObject(name);
	    }
	    /**
	     * {@inheritDoc}
	     */
	    @SuppressWarnings("unchecked")
	    public void save(){
	    	((BaseMapper<T, Serializable>)getMapper()).saveOrUpdate(this);
	    }
	  
	   
}
